package day01;

public class GuardDemo {
    public static void main(String[] args) {
        Runnable r1=()->{
            while(true){
                try {
                    Thread.sleep(500);//控制线程睡眠时间
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("守护线程开始了");
            }
        };
        Runnable r2=()->{
            for (int i = 0; i < 8; i++) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println(i);
            }
        };
        Thread t1=new Thread(r1);
        t1.setDaemon(true);//设置守护线程
        Thread t2=new Thread(r2);
        t1.start();
        t2.start();
    }
}


